home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)in_multiplex.c V1.18 3/13/95";
- #endif
- /*
- | file name - in_multiplex.c
- |===================================================================
- |
- | This program shows how to create the Multiplexor Interaction
- | Handler.
- |
- | The multiplexor is a menu in which each selection activates
- | a different input object. The activated input object is
- | displayed in a shared input area defined by the layout
- | file for the multiplexor. In this example, the user may
- | select between two different slider input objects. The
- | slider input objects control the update of the dial graph.
- |
- | To quit the example use the <q>, <Q> keys or the right mouse
- | button.
- |
- |===================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
- #include "VPfundecl.h" /* VP routines (put info for dgp & vdp) */
- #include "VGfundecl.h" /* VG routines (get info for dgp & vdp) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "multiplex.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- /* Define buffers for input objects */
- float MultiValue = 0.0, /* multiplexor buffer */
- SliderValues[2] = {3.0, 0.0}; /* slider buffers */
-
- /* Define interaction handlers */
- GLOBALREF INHANDLER VNmultiplexor, VNslider;
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location, /* the event representation */
- event_status; /* how the event handler has used the location event */
-
- /* Input object related variables */
- ATTRIBUTES Attributes; /* attribute structure */
- VIEW TemplateView; /* template view */
- OBJECT TemplateDrawing; /* drawing object of template view */
- OBJECT LLcorner, /* lower left pt of input obj */
- URcorner, /* upper right pt of input obj */
- MultiInput, /* multiplexor input obj */
- MultiTech, /* multiplexor input technique obj */
- SliderInput[2], /* embedded input objects */
- SliderTech[2]; /* embedded input objs technique objs */
- VARDESC Vdps[3]; /* variable descriptors for input objs */
-
- /* Graph related variables */
- OBJECT dial_graph; /* graph object */
- DATAGROUP dgp; /* pointer to data group structure */
- VARDESC vdp; /* variable descriptor */
-
- /* Other variables */
- int Quit = NO; /* flag to quit program */
- int i; /* counter */
-
- /*--------------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: open a device as a screen object using
- * specified attributes
- * TscErase: erase the entire screen in the default
- * background color
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS |
- V_MOTIONNOTIFY | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file, either a
- * user supplied view or default view file play.v
- * TdpCreate: Create a DV-Tools window, a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
-
- /*
- * VOdgGetDgp: Returns pointer to the data group structure
- * VGdgvd: Gets the address or number of vdps from the data group
- * TvdPutBuffer: Set a new variable descriptor buffer
- *
- * Rebind the graphs variables to the same buffers that will be
- * controlled by the sliders in the multiplexor.
- */
- dial_graph = TdrGetNamedObject (TviGetDrawing (view), "dial_graph");
- dgp = VOdgGetDgp (dial_graph);
- for (i = 1; i <= (int) VGdgvd (dgp, 0); i++)
- {
- vdp = VGdgvd (dgp, i);
- TvdPutBuffer (vdp, (ADDRESS) &SliderValues[i - 1]);
- }
-
- /*
- * VUerPutKeys: Sets the key-action bindings
- * define the left mouse button as the select
- * keys while the right mouse button will
- * represent the cancel key.
- */
- VUerPutKeys (SELECT_KEYS, "\001");
- VUerPutKeys (CANCEL_KEYS, "\003");
-
- /*
- * VOuAtInit: Sets all attribute fields to EMPTY_FIELD.
- * VOcoCreate: Create a color or RGB object
- * VOptCreate: Create a point object
- *
- * Initialize the attributes structure and fill the fields
- * representing foreground and background color. Also,
- * create the control points to be used by the multiplexor
- * input object and its embedded input objects
- */
- VOuAtInit (&Attributes);
- Attributes.foreground_color = VOcoCreate (COLOR_NAME, "white");
- Attributes.background_color = VOcoCreate (COLOR_NAME, "black");
- LLcorner = VOptCreate (WORLD_COORDINATES, -12000, -12000, (OBJECT) NULL);
- URcorner = VOptCreate (WORLD_COORDINATES, 11000, -4200, (OBJECT) NULL);
-
- /*
- * VOinCreate: Create an input object
- *
- * Create the multiplexor and 2 embedded slider input objects.
- */
- MultiInput = VOinCreate (LLcorner, URcorner, &Attributes);
- SliderInput[0] = VOinCreate (LLcorner, URcorner, &Attributes);
- SliderInput[1] = VOinCreate (LLcorner, URcorner, &Attributes);
-
- /*
- * VPvdcreate: Create a variable descriptor
- * VPvd_drange: Sets the range in doubles.
- * VPvdvarname: Specifies the name of a variable
- *
- * Create the variable descriptors for each of the input objects.
- * The variable descriptors will be bound to program variables.
- */
- Vdps[0] = VPvdcreate ((ADDRESS) & MultiValue, V_F_TYPE);
- VPvd_drange (Vdps[0], (double)0.0, (double)1.0);
- Vdps[1] = VPvdcreate ((ADDRESS) & SliderValues[0], V_F_TYPE);
- VPvdvarname (Vdps[1], "Slider1");
- VPvd_drange (Vdps[1], (double)0.0, (double)18.0);
- Vdps[2] = VPvdcreate ((ADDRESS) & SliderValues[1], V_F_TYPE);
- VPvdvarname (Vdps[2], "Slider2");
- VPvd_drange (Vdps[2], (double)0.0, (double)18.0);
-
- /*
- * VOinPutVarList: Sets the variable descriptor list
- *
- * Set the vdp list for each of the input objects.
- */
- VOinPutVarList (SliderInput[0], (ADDRESS *) Vdps[1], (int)1);
- VOinPutVarList (SliderInput[1], (ADDRESS *) Vdps[2], (int)1);
- VOinPutVarList (MultiInput, (ADDRESS *) Vdps, (int)3);
-
- /*
- * VOitCreate: Create an input technique object
- * VOinTechnique: Sets the input technique to be used for this
- * input object.
- *
- * Load in the layout views which will define the appearance of
- * the embedded slider input objects. The drawing object of the
- * view is obtained and attached to the input technique. The
- * input technique defines the type of input object based on
- * the interaction handler and the appearance is defined by
- * the layout file.
- */
- TemplateView = TviLoad ("DefSlider.lay");
- TemplateDrawing = TviGetDrawing (TemplateView);
- for (i = 0; i <= 1; i++)
- {
- SliderTech[i] = VOitCreate (VNslider, TemplateDrawing);
- VOinTechnique (SliderInput[i], SliderTech[i]);
- }
- TviDestroy (TemplateView);
-
- /*
- * Create the input technique object for the multiplexor input
- * object. Attach the input object and technique together.
- * Also, attach the slider input objects to the multiplexor.
- */
- TemplateView = TviLoad ("Multiplexr.lay");
- TemplateDrawing = TviGetDrawing (TemplateView);
- MultiTech = VOitCreate (VNmultiplexor, TemplateDrawing);
- TviDestroy (TemplateView);
- VOinTechnique (MultiInput, MultiTech);
- VOitPutList (MultiTech, OBJECT_LIST, (ADDRESS) SliderInput, 2);
-
- /*
- * Define key bindings for the multiplexor. The done keys and
- * select keys are bound to the same key binding. This is the
- * recommended practice and is similar to the menu input object.
- */
- VOitPutKeys (MultiTech, SELECT_KEYS, "\001");
- VOitKeyOrigin (MultiTech, SELECT_KEYS, LOCAL_KEYS);
- VOitPutKeys (MultiTech, DONE_KEYS, "\001");
- VOitKeyOrigin (MultiTech, DONE_KEYS, LOCAL_KEYS);
-
- /*
- * VOdrObAdd: Adds an object to the drawing
- *
- * Add the multiplexor input object to the view's drawing.
- * The object will be drawn, updated and redrawn whenever
- * these actions are performed on the drawport containing
- * this view.
- */
- VOdrObAdd (TviGetDrawing (view), MultiInput);
-
- /*
- * TscErase: erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of a drawport
- *
- * Erase the screen and draw the drawport.
- */
- TscErase (screen);
- TdpDraw (drawport);
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for window events specified by the
- * window mask. Handle each of the events as they happen.
- * Events occurring within input objects will be handled
- * through the event request handler VUerHandleLocEvent.
- * Stop when the user selects "q|Q" or the right mouse button.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- *
- * VUerHandleLocEvent: Service the event. This routine will check
- * if the event is used by any input objects
- * that may be in the view.
- */
- location = VOloWinEventPoll (V_WAIT);
- event_status = VUerHandleLocEvent (location);
-
- /*
- * If the return value of VUerHandleLocEvent is INPUT_UNUSED
- * then check for keypress or buttonpress events which
- * represent one of the exit keys.
- */
- if (event_status == INPUT_UNUSED)
- {
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_RESIZE:
- /*
- * TscReset: Resets all screen drawports after
- * window resizing
- * The window size has been changed.
- */
- TscReset (screen);
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
- }
-
- case V_BUTTONPRESS:
- /*
- * Check button selected.
- * VOloButton: Returns the button that was pressed
- *
- * The right mouse button exits the program.
- */
- switch (VOloButton (location))
- {
- case 3:
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- default:
- break;
- }
- }
- else
- /*
- * TdpDrawNext: Updates all dynamic objects
- *
- * Update graph object based on change to sliders
- */
- TdpDrawNext (drawport);
-
- /* exit the program */
- if (Quit == YES)
- break;
- }
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the screen object
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscClose: Closes the screen object
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- TdpDestroy (drawport);
- TviDestroy (view);
- TscClose (screen);
- TTerminate ();
- return (EXIT_OK);
- }
-